package com.ninthgroup.controller;

import com.ninthgroup.entity.Doctor;
import com.ninthgroup.service.DoctorService;
import com.ninthgroup.vo.DoctorVo;
import com.ninthgroup.vo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;
/**
 * @author ：1452863884@qq.com rcg
 * @date ：Created in 2022/10/17 19:19
 * @description：员工(医生)的控制层
 * @modified By：
 * @version:1.0
 */
@RestController
@RequestMapping("/doctor")
public class DoctorController {

    /**
     * @param
     * @return
     * @create by: 1452863884@qq.com rcg
     * @description:logback的具体使用
     * 日志记录器对象
     * @create time: 2022/10/18 10:37
     */
    private static final Logger LOGGER= LoggerFactory.getLogger(DoctorController.class);



    @Autowired
    private DoctorService doctorService;

    @PostMapping("/all")
    public Result selectAll(
            @RequestParam(defaultValue = "1") Integer currentPage,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestBody DoctorVo doctorVo
    ) {
        Result result = doctorService.selectAllAndPage(currentPage, pageSize, doctorVo);
        LOGGER.info("分页的数据:"+ JSON.toJSONString(result));
        return result;
    }

    @GetMapping("/changestatus")
    public Result changestatus(Integer dId,Integer dStatus){
        return doctorService.updateStatus(dId,dStatus);
    }

    @GetMapping("/del")
    public Result delete(Integer dId){
        return doctorService.deleteDid(dId);
    }


    @PostMapping("/update")
    public Result update(@RequestBody Doctor doctor){
        return doctorService.updateDoctor(doctor);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Doctor doctor){
        return doctorService.insertDoctor(doctor);
    }



    @GetMapping("/findOne")
    public Result findOne(Integer dId){
        return doctorService.findOneById(dId);
    }

    @GetMapping("/findMany")
    public Result findManyTable(Integer dId){
        return doctorService.findManyTable(dId);
    }


    @GetMapping("/ds")
    public Result selectAllDoctorAndScheduing(){
        return doctorService.selectAllDoctorAndScheuing();
    }



    //统计医生男女比例
    @RequestMapping("selectSex")
    public Result selectSex() {
        return doctorService.selectBysex();
    }

    //统计医生年龄
    @RequestMapping("selectByAge")
    public Result selectByAge() {
        return doctorService.selectByAge();
    }




}